package io.wongxd.solution.compose.custom.views.value_selector

import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember

/**
 * effect : [WValueSelector] 的状态
 *          State of the [WValueSelector]
 */
class WValueSelectState {
    internal var _lazyListState: LazyListState? = null
    val lazyListState: LazyListState
        get() = _lazyListState!!
    internal var cacheSize = 0
    internal var valueSize = 0
    internal var isLoop = false

    /**
     * 获取当前选中的索引
     * Get current selected index
     */
    fun getSelectIndex(): Int = lazyListState.firstVisibleItemIndex % valueSize + (if (isLoop) cacheSize else 0)
}

/**
 * 创建一个[remember]的[ValueSelectState]
 * Create the [ValueSelectState] of [remember]
 */
@Composable
fun rememberValueSelectState() = remember { WValueSelectState() }